package com.ruoyi.system.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.function.ProdOrder;
import com.ruoyi.system.domain.prod.ProdCountByTaskTonDTO;
import com.ruoyi.system.domain.prod.ProdPsInfoVO;
import com.ruoyi.system.domain.prod.QueryProdPsInfoDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 工单信息Mapper接口
 *
 * @author ruoyi
 * @date 2023-02-13
 */
public interface ProdOrderMapper extends BaseMapper<ProdOrder> {

    @Select("select ISNULL(sum(t.order_number),0) sumOr,t.task_ton,t.product_code from prod_order t where t.order_state=3 \n" +
            "and t.task_ton in\n" +
            "(select task_ton taskTon from prod_plan t\n" +
            "where t.end_time>=#{date20Str} and t.end_time<=#{date05Str} and ${ifTask} GROUP BY t.task_ton)\n" +
            "GROUP BY t.task_ton,t.product_code")
    List<ProdCountByTaskTonDTO> selectByTaskTon(@Param("date20Str")String date20Str,@Param("date05Str") String date05Str,@Param("ifTask") String ifTask);

    @Select("select t1.product_code,t.task_ton,t2.child_code,ISNULL(sum(t.order_number),0) sumBom from prod_order t INNER JOIN prod_plan t1 on t.plan_code=t1.plan_code\n" +
            "INNER JOIN bom_info_erp t2 on t1.scdd_erp_id=t2.scdd_erp_id where t.order_state=3\n" +
            "and t.task_ton in\n" +
            "(select task_ton taskTon from prod_plan t\n" +
            "where  t.end_time>=#{yesterday20Str} and t.end_time<=#{date05Str} and t.if_bom_task=0  GROUP BY t.task_ton)\n" +
            "GROUP BY t.task_ton,t2.child_code,t1.product_code")
    List<ProdCountByTaskTonDTO> selectByChildCode(@Param("yesterday20Str") String yesterday20Str, @Param("date05Str") String date05Str);

    List<ProdPsInfoVO> selectPsInfo(QueryProdPsInfoDTO dto);
}
